package cn.aposoft.mq.kafka.admin.topic;

import org.apache.kafka.clients.admin.*;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.KafkaFuture;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class CreatePartitions {

    public static void main(String[] args) {
        final String topicName = "quickstart-events";
        Properties p = new Properties();
        p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "aposoft.cn:10091");// kafka地址，多个地址用逗号分割
        try (Admin admin = Admin.create(p);) {
            NewPartitions partitions = NewPartitions.increaseTo(2);
            CreatePartitionsResult pResult = admin.createPartitions(Collections.singletonMap(topicName, partitions));
            KafkaFuture<Void> pfuture = pResult.all();
            pfuture.get();
            DescribeTopicsResult tResult = admin.describeTopics(Collections.singleton(topicName));
            System.out.println(tResult.all().get());
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
